#include <sys/mman.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>

/* 
size of each memory segment, allocated by mmap.
if the user asks for a malloc that is bigger then this, a special memory segment is allocated, in the needed size. 
*/
#define MEM_SEGMENT_SIZE 100000

/* size of the header of each memory segment, allocated by mmap */
#define MEM_SEGMENT_HEADER_SIZE (2*sizeof(void*)+sizeof(size_t))
/* location of the "size" of the memory segment, inside its header */
#define SIZE sizeof(void*)
/* location of the pointer to the next memory segment, inside the header */
#define NEXT (sizeof(void*)+sizeof(size_t))
/* a pointer to the first free segment (the smallest) is written in the beginning of the header */

/* size of the header of each allocated/free segment inside the memory segment */
#define SEGMENT_HEADER_SIZE (2*sizeof(void*)+sizeof(size_t))
/* location of the pointer to the next free segment in the "free list", inside the header */
#define NEXT_FREE (sizeof(size_t)+sizeof(char))
/* location of the pointer to the previous free segment in the "free list", inside the header */
#define PREV_FREE (sizeof(size_t)+sizeof(char)+sizeof(void*))
/* the size of the segment is written in the beginning of its header */

/* same as malloc */
void* myMalloc (size_t);
/* same as free */
void myFree (void*);
/*
frees the memory allocated by the program and used for myMalloc and myFree.
should be used when exiting the program.
*/
void freeAll();
